package com.sunkingdom.qq.user.controller.impl;

import com.sunkingdom.qq.global.Result;
import com.sunkingdom.qq.user.controller.RegisterController;
import com.sunkingdom.qq.user.entity.User;
import com.sunkingdom.qq.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(value = "/register")
public class RegisterControllerImpl implements RegisterController {
	private static final String USER_REGIST = "user/user-regist";
	
	@Autowired
	private User user;
	@Autowired
	private UserService userService;

	@RequestMapping(value = "/user", method = RequestMethod.POST)
	public String registUser(HttpServletRequest request,
			HttpServletResponse response) {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		user.setUsername(username);
		user.setPassword(password);
		userService.addUser(user);
		request.setAttribute(Result.MESSAGE, "regist success: " + username
				+ "/" + password);
		return Result.RESULT;
	}

	@RequestMapping(value = "/user", method = RequestMethod.GET)
	public String userRegistPage(HttpServletRequest request,
			HttpServletResponse response) {
		return USER_REGIST;
	}

}
